import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/constants/constant.dart';
import 'package:flutter_eve_plugin/model/app_info.dart';
import 'package:flutter_eve_plugin/model/base_res.dart';
import 'package:flutter_eve_plugin/model/health/health_log.dart';
import 'package:flutter_eve_plugin/model/health/sys_health_property.dart';
import 'package:flutter_eve_plugin/model/health/user_body_property.dart';
import 'package:flutter_eve_plugin/model/health/user_info.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_ability_detail_entity.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_ability_entity.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_form_entity.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_role_entity.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_weapon_entity.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/card/card.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/card/weapon.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/dungeon_rank.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/dungeons.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/fight_succ.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/stageinfo.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/stages.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/user_card.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/vitality.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/login/area_code.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/login/bind_result.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/rank/rank_info.dart';
import 'package:flutter_eve_plugin/route/main.dart';
import 'package:flutter_eve_plugin/utils/event_bus.dart';
import 'package:flutter_eve_plugin/utils/print_util.dart';

void receiveRoute() {
  bus.on(PluginConstant.PUSH_CODE, (code) {
    String pushName;
    switch (code) {
      case PluginConstant.nativeHealthHome:
        pushName = RouteConstant.HealthMainPage;
        break;
      case PluginConstant.nativeHealthWeight:
        pushName = RouteConstant.WeightDetailsPage;
        break;
      case PluginConstant.nativeLogin:
        pushName = RouteConstant.LoginMainPage;
        break;
      case PluginConstant.nativeEditUser:
        pushName = RouteConstant.LoginBirthdayPage;
        break;
      case PluginConstant.nativeSelectMachine:
        pushName = RouteConstant.LoginSelectMachinePage;
        break;
      case PluginConstant.nativeRankList:
        pushName = RouteConstant.RankListMainPage;
        break;
      case PluginConstant.nativeCheckpoint:
        pushName = RouteConstant.CheckpointMainPage;
        break;
      case PluginConstant.nativeArchives:
        pushName = RouteConstant.ArchivesMainPage;
        break;
    }
    initPushName = pushName;
    NavigatorState navState = navigatorKey.currentState;
    navState.pushAndRemoveUntil(
        PageRouteBuilder(pageBuilder: (context, animation, secondaryAnimation) {
      return findRouteWidget(context, pushName);
    }), (Route<dynamic> route) => false);
  });
}

dynamic httpModelFilter(String httpKey, jsonRes) {
  try {
    switch (httpKey) {
      case PluginConstant.httpHealthHome:
        return PropertyHealthModel.fromJson(jsonRes['data']);
      case PluginConstant.httpHealthBody:
        return UserBodyModel.fromJson(jsonRes);
      case PluginConstant.httpUserInfo:
        logDebugPrint('httpUserInfo $jsonRes');
        return UserInfoModel.fromJson(jsonRes);
      case PluginConstant.httpHealthLog:
        return HealthLogModel.fromJson(jsonRes['data']);
      case PluginConstant.httpYXAreaCode:
        return AreaCodeRes.fromJson(jsonRes);
      case PluginConstant.httpYXCaptcha:
        return BaseRes.fromJson(jsonRes);
      case PluginConstant.httpYXRegMobile:
        return AccountInfo.fromJson(jsonRes['data']);
      case PluginConstant.httpYXAppInfo:
        return AppInfo.fromJson(jsonRes);
      case PluginConstant.httpYXEditUserInfo:
        return BaseRes.fromJson(jsonRes);
      case PluginConstant.httpYXBindResult:
        return BindResultModel.fromJson(jsonRes);
      case PluginConstant.httpAccountInfo:
        return AccountInfo.fromJson(jsonRes);
      case PluginConstant.httpYXAutoLogin:
        return AccountInfo.fromJson(jsonRes['data']);
      case PluginConstant.httpYXSwitchIP:
        return BaseRes.fromJson(jsonRes);
      case PluginConstant.httpYXAchievesRole:
        return ArchievesRoleEntity.fromJson(jsonRes['data']);
      case PluginConstant.httpYXAchievesWeapon:
        return ArchievesWeaponEntity.fromJson(jsonRes['data']);
      case PluginConstant.httpYXWeaponForm:
        return ArchievesFormEntity.fromJson(jsonRes);
      case PluginConstant.httpYXAbilityDetail:
        return ArchievesAbilityDetailEntity.fromJson(jsonRes['data']);
      case PluginConstant.httpYXPersonalData:
        return ArchievesAbilityEntity.fromJson(jsonRes);
      case PluginConstant.httpYXGetCoinRanking:
      case PluginConstant.httpYXGetRanking:
      case PluginConstant.httpYXGetAbilityRanking:
        return RankInfo.fromJson(jsonRes);
      case PluginConstant.httpYXWeaponUpgrade:
        return WeaponUpgrade.fromJson(jsonRes);
      case PluginConstant.httpYXFormUpgrade:
        return WeaponFormInfo.fromJson(jsonRes);
      case PluginConstant.httpYXCardUpgrade:
        return CardUpgrade.fromJson(jsonRes);
      case PluginConstant.httpYXDungeons:
        return CheckpointDungeons.fromJson(jsonRes['data']);
      case PluginConstant.httpYXDungeonStages:
        return CheckpointStages.fromJson(jsonRes['data']);
      case PluginConstant.httpYXDungeonStageInfo:
        return CheckpointStageInfo.fromJson(jsonRes['data']);
      case PluginConstant.httpYXDungeonRank:
        return DungeonRank.fromJson(jsonRes['data']);
      case PluginConstant.httpYXDungeonVitality:
        return DungeonVitality.fromJson(jsonRes['data']);
      case PluginConstant.httpYXUserCard:
        return UserCard.fromJson(jsonRes['data']);
      case PluginConstant.httpYXDungeonFight:
        return FightSucc.fromJson(jsonRes['data']);
    }
  } catch (e) {
    logPrint('$httpKey 解析出错 $e');
    return null;
  }
  logPrint('$httpKey 未加入解析');
  return null;
}
